import 'package:flutter/material.dart';
import 'package:flutter_app/beautyPage.dart';
import 'package:flutter_app/cupertino/eg_CupertinoAlertDialog.dart';
import 'package:flutter_app/cupertino/eg_CupertinoButton.dart';
import 'package:flutter_app/cupertino/eg_CupertinoNav.dart';
import 'package:flutter_app/cupertino/eg_Indicator.dart';
import 'package:flutter_app/layout/eg_Center.dart';
import 'package:flutter_app/layout/eg_Container.dart';
import 'package:flutter_app/layout/eg_Padding.dart';
import 'package:flutter_app/material/AlertDialogSample.dart';
import 'package:flutter_app/material/DrawerSample.dart';
import 'package:flutter_app/material/FloatingActionButtonSample.dart';
import 'package:flutter_app/material/PopupMenuButtonSample.dart';
import 'package:flutter_app/material/SimpleDialogSample.dart';
import 'package:flutter_app/material/StateSample.dart';
import 'package:flutter_app/material/TabBarSample.dart';
import 'package:flutter_app/material/egAppBar.dart';
import 'package:flutter_app/material/egBottomNavigationBar.dart';
import 'package:flutter_app/material/egScaffold.dart';
import 'package:flutter_app/material/egTabBar.dart';
import 'package:flutter_app/widgets/eg_Card.dart';
import 'package:flutter_app/widgets/eg_TextField.dart';

///MaterialApp 代表 纸模设计风格的应用
/// 主要属性：
/// title ： 指定应用程序的标题（Android 任务管理器快照上出现 iOS 程序切换器中出现）
/// home: 这是一个Widget 对象，执行当前应用打开显示的页面
/// theme ：主题
/// routes : 定义应用中页面跳转的规则 <String,WidgetBuilder>
/// initialRoute : 初始化路由页面（指定默认的启动页面）
class MaterialAppDemo extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    final _title = "MaterialApp 演示";
    return new MaterialApp(
      title: _title,
      home: new MyHomePage(),

      ///注意这里的路由名字
      routes: {
        "/first": (BuildContext context) => FirstPage(),
        "/second": (BuildContext context) => SecondPage(),
        "/scaffold": (BuildContext context) => ScaffoldDemo(),
        "/appBarDemo": (BuildContext context) => AppBarDemo(),
        "/bottomNavigationBar": (BuildContext context) => EgBottomNavigation(),
        "/defaultTabControllerSample": (BuildContext context) => DefaultTabControllerSample(),
        "/TabBarSample": (BuildContext context) => TabBarSample(),
        "/DrawerSample": (BuildContext context) => DrawerSample(),
        "/floatingButtonSample": (BuildContext context) => FloatingButtonSample(),
        "/PopupMenuButtonSample": (BuildContext context) => PopupMenuButtonSample(),
        "/SimpleDialogSample": (BuildContext context) => SimpleDialogSample(),
        "/AlertDialogSample": (BuildContext context) => AlertDialogSample(),
        "/stateTest": (BuildContext context) => StateSample(
              title: "测试状态组件",
            ),
        "/TextField": (BuildContext context) => EgTextField(),
        "/EgCard": (BuildContext context) => EgCard(),
        "/home": (BuildContext context) => MyHomePage(),
        "/cupertinoActivityIndicator": (BuildContext context) => EgIndicator(),
        "/EGCupertinoAlertDialog": (BuildContext context) => EGCupertinoAlertDialog(),
        "/EGCupertinoButton": (BuildContext context) => EGCupertinoButton(),
        "/EgCupertinoNav": (BuildContext context) => EgCupertinoNavState(),
        "/EgContainer": (BuildContext context) => EgContainer(),
        "/EgCenter": (BuildContext context) => EgCenter(),
        "/EgPadding": (BuildContext context) => EgPadding(),
        "/BeautyPage": (BuildContext context) => BeautyPage(),
      },
//      initialRoute: "/home",

      theme: new ThemeData(
        primaryColor: Colors.red,
      ),
    );
  }
}

class MyHomePage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return _MyHomePageState();
  }
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    final _title = "MaterialApp 演示";
    return new Scaffold(
      appBar: new AppBar(title: new Text(_title)),
      body: Center(
        child: new SingleChildScrollView(
          child: new Column(
            children: <Widget>[
              new Text(
                "主页",
                style: TextStyle(fontSize: 22),
              ),
              RaisedButton(
                onPressed: () {
                  Navigator.pushNamed(context, "/scaffold");
                },
                child: new Text(
                  "跳转到scaffold演示",
                  style: TextStyle(fontSize: 18),
                ),
              ),
              RaisedButton(
                onPressed: () {
                  Navigator.pushNamed(context, "/bottomNavigationBar");
                },
                child: new Text(
                  "跳转到底部菜单页面",
                  style: TextStyle(fontSize: 18),
                ),
              ),
              RaisedButton(
                onPressed: () {
                  Navigator.pushNamed(context, "/defaultTabControllerSample");
                },
                child: new Text(
                  "跳转到横向选项卡页面",
                  style: TextStyle(fontSize: 18),
                ),
              ),
              RaisedButton(
                onPressed: () {
                  Navigator.pushNamed(context, "/TabBarSample");
                },
                child: new Text(
                  "跳转到多Tab切换页面",
                  style: TextStyle(fontSize: 18),
                ),
              ),
              RaisedButton(
                onPressed: () {
                  Navigator.pushNamed(context, "/DrawerSample");
                },
                child: new Text(
                  "跳转到Drawer页面",
                  style: TextStyle(fontSize: 18),
                ),
              ),
              RaisedButton(
                child: new Text(
                  "跳转到FloatingActionButton页面",
                  style: TextStyle(fontSize: 18),
                ),
                onPressed: () {
                  Navigator.pushNamed(context, "/floatingButtonSample");
                },
              ),
              RaisedButton(
                child: new Text(
                  "跳转到PopupMenuButton页面",
                  style: TextStyle(fontSize: 18),
                ),
                onPressed: () {
                  Navigator.pushNamed(context, "/PopupMenuButtonSample");
                },
              ),
              RaisedButton(
                child: new Text(
                  "跳转到SimpleDialogSample页面",
                  style: TextStyle(fontSize: 18),
                ),
                onPressed: () {
                  Navigator.pushNamed(context, "/SimpleDialogSample");
                },
              ),
              RaisedButton(
                child: new Text(
                  "AlertDialogSample",
                  style: TextStyle(fontSize: 18),
                ),
                onPressed: () {
                  Navigator.pushNamed(context, "/AlertDialogSample");
                },
              ),
              RaisedButton(
                child: new Text(
                  "EgCard",
                  style: TextStyle(fontSize: 18),
                ),
                onPressed: () {
                  Navigator.pushNamed(context, "/EgCard");
                },
              ),
              RaisedButton(
                child: new Text(
                  "cupertinoActivityIndicator",
                  style: TextStyle(fontSize: 18),
                ),
                onPressed: () {
                  Navigator.pushNamed(context, "/cupertinoActivityIndicator");
                },
              ),
              RaisedButton(
                child: new Text(
                  "CupertinoAlertDialog",
                  style: TextStyle(fontSize: 18),
                ),
                onPressed: () {
                  Navigator.pushNamed(context, "/EGCupertinoAlertDialog");
                },
              ),
              RaisedButton(
                child: new Text(
                  "EGCupertinoButton",
                  style: TextStyle(fontSize: 18),
                ),
                onPressed: () {
                  Navigator.pushNamed(context, "/EGCupertinoButton");
                },
              ),
              RaisedButton(
                child: new Text(
                  "EgCupertinoNav",
                  style: TextStyle(fontSize: 18),
                ),
                onPressed: () {
                  Navigator.pushNamed(context, "/EgCupertinoNav");
                },
              ),
              RaisedButton(
                child: new Text(
                  "BeautyPage",
                  style: TextStyle(fontSize: 18),
                ),
                onPressed: () {
                  Navigator.pushNamed(context, "/BeautyPage");
                },
              ),
            ],
          ),
        ),
      ),
    );
  }
}

class FirstPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        title: new Text("FirstPage"),
      ),
      body: Center(
        child: RaisedButton(
          onPressed: () {
            Navigator.pushNamed(context, "/second");
          },
          child: new Text(
            "这是第一个页面",
            style: TextStyle(fontSize: 28),
          ),
        ),
      ),
    );
  }
}

class SecondPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        title: new Text("SecondPage"),
      ),
      body: Center(
        child: RaisedButton(
          onPressed: () {
            Navigator.pushNamed(context, "/first");
          },
          child: new Text(
            "这是第二个页面",
            style: TextStyle(fontSize: 28),
          ),
        ),
      ),
    );
  }
}
